package com.ytjj.qmyx.admin.config;


import com.ytjj.common.utils.SignUtil;
import lombok.Data;
import org.apache.commons.collections.map.LinkedMap;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.TreeMap;


/**
 * 供应链配置
 */
@Data
@Component
@RefreshScope
public class SupplyApiConfig {

    @Value("${supply.api.url}")
    private String url;

    @Value("${supply.api.source}")
    private String source;

    @Value("${supply.api.partentId}")
    private String partentId;

    @Value("${supply.api.partentKey}")
    private String partentKey;

    @Value("${supply.api.shopId}")
    private String shopId;

    /**
    * 封装请求头数据
    * @param :
    * @returns: java.util.Map<java.lang.String,java.lang.String>
    * 
    */
    public Map<String,String> getHeadsMap(){
        Map<String,String> map = new TreeMap();
        map.put("contentType","json");
        map.put("timestamp", String.valueOf(System.currentTimeMillis()));
        map.put("source",getSource());
        map.put("partentId", getPartentId());
        map.put("partentKey", getPartentKey());
        //生成签名
        String sign = SignUtil.sign("json", "weapp", getPartentId(),getPartentKey(),map.get("timestamp"));
        map.put("sign", sign);
        return map;
    }

}
